package com.ktwlsoft.archivemanage.domain.business.repositoryService;

import com.ktwlsoft.archivemanage.domain.dao.entity.ActionSource;
import com.ktwlsoft.archivemanage.domain.dao.entity.RoleActionRelation;
import com.ktwlsoft.archivemanage.domain.dao.repository.IRoleActionMapper;
import com.ktwlsoft.archivemanage.payload.exception.BusinessException;
import com.ktwlsoft.archivemanage.payload.role.EditRoleRequest;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleActionRepositoryService {

    private final IRoleActionMapper roleActionMapper;

    public RoleActionRepositoryService(IRoleActionMapper roleActionMapper) {
        this.roleActionMapper = roleActionMapper;
    }

    public int deleteByRoleId(Long roleId){
        return roleActionMapper.deleteByRoleId(roleId);
    }

    public int save(RoleActionRelation roleActionRelation){
        return roleActionMapper.insertRoleAction(roleActionRelation);
    }

    public int updateRoleInfo(EditRoleRequest request) {
        return roleActionMapper.updateRoleInfo(request);
    }

    public boolean existsByRoleId(Long roleId) {
        return roleActionMapper.findByRoleId(roleId).size()>0;
    }
}
